package com.zzh.controller.home;

import com.zzh.entity.TabEntity;
import com.zzh.redis.RedisTemplaUtlis;
import com.zzh.service.home.HomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/tab")
public class HomeServiceController {
    @Autowired
    private HomeService homeService;
    @Autowired
    private RedisTemplaUtlis redisTemplaUtlis;

    /****
     * cacheNames 指的是文件夹
     *
     *
     * @return
     */
    @RequestMapping("/list")
    @Cacheable(cacheNames = "tabs" ,key = "'getTabName'") // 通过注解形式添加redis 缓存 key 一定要加单引号
    public List<TabEntity> getTabName() {
        TabEntity tabEntity = new TabEntity();
        List<TabEntity> list = homeService.list(tabEntity);
        redisTemplaUtlis.setObject("tabs", list);
        return list;
    }

    @RequestMapping("/listRedis")
    public List<TabEntity> getTabNameByredis() {
        return (List<TabEntity>) redisTemplaUtlis.getObject("tabs");
    }

}
